﻿using System;
using System.Collections.Generic;
using System.Text;

namespace caputretool
{
    class EditWin
    {
        public EditWin()
        {
            this.window = BITUI.AppFramework.CreateWindow("Caputre Tool V0.01" //标题
                , 64, 40//tile数 宽, 高
                , BITUI.WindowOption_ScaleMode.AutoTileCount, false //随屏幕改变tile数，不插值（SDL的插值太恶心）
                , 3.0f //像素缩放比
                );
            this.OnInit();
            this.window.eventOnUpdate += this.OnUpdate;
        }
        public BITUI.Window window
        {
            get;
            private set;
        }
        BITUI.Tile.Bank bank0;
        BITUI.Tile.Scale9 scale9_border01;
        BITUI.Element.Label label_forFPS;
        //element struct

        //root("canvas")
        //----splitPanel  Left/Right
        //--------splitPanel LeftTop/LeftBottom
        //--------splitPanel RightTop/RightBottom
        //----label forFPS
        void OnInit()
        {
            //window 一定会有一个bank0,如无特别需求，不需要增加新的bank,所有的图块素材都可以放在这个bank里面
            this.bank0 = window.GetBank(0);

            //加载中英文字库 12点阵，这个文件在BITUI库中
            BITUI.Tile.TileTool.LoadASCII12toBank(bank0); //英文12点阵字库 ，8字库太小了
            BITUI.Tile.TileTool.LoadHZK12toBank(bank0);//中文12点阵字库，中文能显示清楚12最合适

            //一个scale9，可以缩放的元素，适合来做边框
            scale9_border01 = BITUI.Tile.Scale9.CreateTwoBorderScale9(bank0, "s9border_01");


            var canvasRoot = new BITUI.Element.Canvas();
            //canvasRoot.backGround = scale9_border01;

            var split = new BITUI.Element.SplitPanel();
            var split_Left = new BITUI.Element.SplitPanel();
            var split_Right = new BITUI.Element.SplitPanel();

            //split.backGround = scale9_border01;
            split.TileYLocal = 1;
            split.dockMode = BITUI.Element.PanelADock.LeftPercent;
            split.dockValue = 50;
            split.dockSplitSize = 1;
            //split.panelA.backGround = scale9_border01;
            //split.panelB.backGround = scale9_border01;



            //一个scale9，可以缩放的元素，适合来做边框
            //split_Left.backGround = scale9_border01;

            split_Left.dockMode = BITUI.Element.PanelADock.TopPercent;
            split_Left.dockValue = 50;
            split_Left.panelA.backGround = scale9_border01;
            split_Left.panelB.backGround = scale9_border01;



            split_Right.dockMode = BITUI.Element.PanelADock.TopPercent;
            split_Right.dockValue = 50;
            split_Right.panelA.backGround = scale9_border01;
            split_Right.panelB.backGround = scale9_border01;

            //add label_forFPS
            label_forFPS = new BITUI.Element.Label(bank0, "fps=0");
            label_forFPS.TileXLocal = 2;
            label_forFPS.TileWidth = 8;
            label_forFPS.backGround = BITUI.Tile.TileTool.LoadBlock(bank0);//加载个实心块
            label_forFPS.backGroundColorReplace = 0x0E;
            label_forFPS.HAlign = BITUI.Element.HAlign.Center;


            window.RootElement = canvasRoot;
            canvasRoot.AddChild(split);
            split.panelA.AddChild(split_Left);
            split.panelB.AddChild(split_Right);
            canvasRoot.AddChild(label_forFPS);
            InitPanelLeftTop(split_Left.panelA);
            InitPanelLeftBottom(split_Left.panelB);
            InitPanelRightTop(split_Right.panelA);
            InitPanelRightBottom(split_Right.panelB);
        }

        void InitPanelLeftTop(BITUI.Element.IElement2DGroup root)
        {

        }
        void InitPanelLeftBottom(BITUI.Element.IElement2DGroup root)
        {

        }
        void InitPanelRightTop(BITUI.Element.IElement2DGroup root)
        {

        }
        void InitPanelRightBottom(BITUI.Element.IElement2DGroup root)
        {

        }
        //update 固定60帧，当然用帧计时掉帧时会卡，如果要用deltatime计时法，需要自己加。
        void OnUpdate()
        {
            label_forFPS.text = "fps=" + BITUI.AppFramework.Fps.ToString("F2");
        }
    }
}
